#include <cstdio>
#include <iostream>
#define MAXN 45233
using namespace std;

int k, n;
int w[MAXN], f[MAXN];

inline int read() {
	int k = 0;
	char c = getchar();
	for(;!isdigit(c); c = getchar());
	for(; isdigit(c); c = getchar())
		k = k * 10 + c - '0';
	return k;
}

int main() {
#ifndef LOCAL
	freopen("diet.in", "r", stdin);
	freopen("diet.out", "w", stdout);
#endif 
	k = read();
	n = read();
	for(int i = 1; i <= n; i++) {
		w[i] = read();
		for(int j = k; j >= w[i]; j--) {
			f[j] = max(f[j], f[j - w[i]] + w[i]);
		}
	}
	
	printf("%d",f[k]);
}
